import Vue from 'vue'
import Router from 'vue-router'
import Demo from '@/components/aemo/aemo'
import NotFound from '@/components/404'
import PageTransition from '@/components/pageTransition/pageTransition'
import Home from '@/components/home/home'
import GooodsDetail from '@/components/goodsDetail/goodsDetail'
import Shopcar from '@/components/shopcar/shopcar'
import OrderConfirm from '@/components/orderConfirm/orderConfirm'
import OrderGoodsList from '@/components/orderGoodsList/orderGoodsList'

import Recommend from '@/components/recommend/recommend'

import UserCenter from '@/components/userCenter/userCenter'

import AddressList from '@/components/addressList/addressList'
import AddAddress from '@/components/addAddress/addAddress'
import EditAddress from '@/components/editAddress/editAddress'

import AccountSet from '@/components/accountSet/accountSet'
import OrderList from '@/components/orderList/orderList'
import OrderDetail from '@/components/orderDetail/orderDetail'
import BindTel from '@/components/bindTel/bindTel'
import Login from '@/components/login/login'

Vue.use(Router)

let router = new Router({
  mode: 'history',
  routes: [{
    path: '/',
    component: PageTransition, // 引入页面切换组件,
    children: [{
      path: '/demo',
      name: 'demo',
      meta: {
        title: 'Demo'
      },
      component: Demo
    }, {
      path: '/',
      name: 'home',
      alias: '/home',
      meta: {
        title: '主页 - 优好生活'
      },
      component: Home
    }, {
      path: '/detail',
      name: 'detail',
      meta: {
        title: '商品详情 - 优好生活'
      },
      component: GooodsDetail
    }, {
      path: '/recommend',
      name: 'recommend',
      meta: {
        title: '您的推荐 - 优好生活'
      },
      component: Recommend
    }, {
      path: '/shopcar',
      name: 'shopcar',
      meta: {
        title: '购物车 - 优好生活'
      },
      component: Shopcar
    }, {
      path: '/orderconfirm',
      name: 'orderConfirm',
      meta: {
        title: '订单确认 - 优好生活'
      },
      component: OrderConfirm
    }, {
      path: '/ordergoodslist',
      name: 'ordergoodslist',
      meta: {
        title: '商品列表 - 优好生活'
      },
      component: OrderGoodsList
    }, {
      path: '/user',
      name: 'user',
      meta: {
        title: '个人中心 - 优好生活'
      },
      component: UserCenter
    }, {
      path: '/user/addresslist',
      name: 'addresslist',
      meta: {
        title: '地址中心 - 优好生活'
      },
      component: AddressList
    }, {
      path: '/user/addaddress',
      name: 'addaddress',
      meta: {
        title: '添加地址 - 优好生活'
      },
      component: AddAddress
    }, {
      path: '/user/editaddress',
      name: 'editaddress',
      meta: {
        title: '修改地址 - 优好生活'
      },
      component: EditAddress
    }, {
      path: '/user/account',
      name: 'account',
      meta: {
        title: '账号及安全 - 优好生活'
      },
      component: AccountSet
    }, {
      path: '/user/orderlist',
      name: 'orderlist',
      meta: {
        title: '订单列表 - 优好生活'
      },
      component: OrderList
    }, {
      path: '/user/orderdetail',
      name: 'orderdetail',
      meta: {
        title: '订单详情 - 优好生活'
      },
      component: OrderDetail
    }, {
      path: '/user/bind',
      name: 'bind',
      meta: {
        title: '换绑手机 - 优好生活'
      },
      component: BindTel
    }, {
      path: '/login',
      name: 'login',
      meta: {
        title: '登录 - 优好生活'
      },
      component: Login
    }, {
      path: '*',
      component: NotFound,
      meta: {
        title: '找不到页面'
      }
    }]
  }]
})

router.beforeEach((to, from, next) => {
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

// router.go = function() {
//   this.isBack = true
//   window.history.go(-1)
// }

export default router
